<!-- HTML header for doxygen 1.8.13-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>MTB CAT1 Peripheral driver library: Client-Server Model</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen_style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><a href="http://www.cypress.com/"><img alt="Logo" src="IFXCYP_one-line.png"/></a></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">MTB CAT1 Peripheral driver library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('group__group__crypto__cli__srv.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#groups">API Reference</a>  </div>
  <div class="headertitle">
<div class="title">Client-Server Model<div class="ingroups"><a class="el" href="group__group__crypto.html">Crypto       (Cryptography)</a></div></div>  </div>
</div><!--header-->
<div class="contents">
<a name="details" id="details"></a><h2 class="groupheader">General Description</h2>
<p>Use the client-server API to isolate the Crypto hardware from non-secure application access. </p>
<p>The functions and other declarations used in this part of the driver are in cy_crypto.h and cy_crypto_server.h. You can also include cy_pdl.h to get access to all functions and declarations in the PDL.</p>
<p>The firmware initializes and starts the Crypto server. The server can run on any core and works with the Crypto hardware. The Crypto server is implemented as a secure block. It performs all cryptographic operations for the client. Access to the server is through the Inter Process Communication (IPC) driver. Direct access is not allowed.</p>
<p>The Crypto client can run on any core too. The firmware initializes and starts the client. The firmware then provides configuration data required for the desired cryptographic technique and a request that the server run the cryptographic operation.</p>
<p>Note that Client-server model is not supported when DCache is enabled.</p>
<p>This document contains the following topics:</p><ul>
<li><a class="el" href="group__group__crypto__cli__srv.html#group_crypto_architecture">Architectural model</a></li>
<li><a class="el" href="group__group__crypto__cli__srv.html#group_crypto_configuration_structure">Configuration Structure</a></li>
<li><a class="el" href="group__group__crypto__cli__srv.html#group_crypto_server_init">Server Initialization</a></li>
<li><a class="el" href="group__group__crypto__cli__srv.html#group_crypto_client_init">Client initialization</a></li>
<li><a class="el" href="group__group__crypto__cli__srv.html#group_crypto_common_use_cases">Common Use Cases</a></li>
<li><a class="el" href="group__group__crypto__cli__srv.html#group_crypto_rsa_considerations">RSA Usage Considerations</a></li>
<li><a class="el" href="group__group__crypto__cli__srv.html#group_crypto_irq_implements">Implementing Crypto Interrupts</a></li>
<li><a class="el" href="group__group__crypto.html#group_crypto_definitions">Definitions</a></li>
<li><a class="el" href="group__group__crypto.html#group_crypto_more_information">More Information</a></li>
</ul>
<h1><a class="anchor" id="group_crypto_architecture"></a>
Architectural model</h1>
<p>The client-server implementation uses:</p><ul>
<li>one IPC channel for data exchange between client and server applications;</li>
<li>three interrupts: an IPC notify interrupt, an IPC release interrupt, and an interrupt for error handling.</li>
</ul>
<p>Firmware initializes and starts the Crypto server. The server can run on any core and works with the Crypto hardware. The Crypto server is implemented as a secure block. It performs all cryptographic operations for the client. Access to the server is through the Inter Process Communication (IPC) driver. Direct access is not allowed.</p>
<p>The Crypto client can also run on any core. Firmware initializes and starts the client. The firmware then provides the configuration data required for the desired cryptographic technique, and requests that the server run the cryptographic operation.</p>
<dl class="section note"><dt>Note</dt><dd>Only one Crypto server and only one Crypto client can be run at the same time on any core. So, valid configurations are:<ul>
<li>one server instance runs on CM0+ and one client instance on CM4 (and vice versa).</li>
<li>one server instance and one client instance run on CM0+ (<b>** This is not recommended, use Direct Crypto API's to perform Crypto operations on a single core</b>).</li>
<li>one server instance and one client instance run on CM4 (<b>** This is not recommended, use Direct Crypto API's to perform Crypto operations on a single core</b>).</li>
</ul>
</dd></dl>
<div class="image">
<img src="crypto_architecture.png" alt="crypto_architecture.png"/>
</div>
<p>IPC communication between the client and server is completely transparent. Using IPC for communication provides a simple synchronization mechanism to handle concurrent requests from different cores.</p>
<h1><a class="anchor" id="group_crypto_configuration_structure"></a>
Configuration Structure</h1>
<p>IPC communication for the Crypto driver is handled transparently. User should select the IPC channel, and configure the required notify, release, and error interrupts.</p>
<p>These initialization routines, <a class="el" href="group__group__crypto__srv__functions.html#ga1b6e8094edd6fa456da67f4b31ab754b">Cy_Crypto_Server_Start</a> (server) and <a class="el" href="group__group__crypto__cli__functions.html#ga79963cfa80b828a77a85bd8e144af2e1">Cy_Crypto_Init</a> (client), use separate instances of the same <a class="el" href="structcy__stc__crypto__config__t.html" title="The Crypto configuration structure. ">cy_stc_crypto_config_t</a> configuration structure. Some fields should be the same, and some are set specifically by either the server or client. The table lists each field in the config structure, and which initialization routine sets the value.</p>
<table class="doxtable">
<tr>
<th>Field</th><th>Which</th><th>Description</th><th>Notes </th></tr>
<tr>
<td><a class="el" href="structcy__stc__crypto__config__t.html#abef76d6d8c3b14def789a9700ba9389d">ipcChannel</a> </td><td>Server and Client </td><td>IPC channel for communication between client and server </td><td>IPC Channel, same for both  </td></tr>
<tr>
<td><a class="el" href="structcy__stc__crypto__config__t.html#abaea23dcf6f3e7c467646f73b2f9772d">acquireNotifierChannel</a> </td><td>Server and Client </td><td>IPC interrupt structure used for the new request notifications </td><td>Notify interrupt number, for Server side only  </td></tr>
<tr>
<td><a class="el" href="structcy__stc__crypto__config__t.html#ac0565f33722a6688fa31e0fc134ac0bd">releaseNotifierChannel</a> </td><td>Server and Client </td><td>IPC interrupt structure used for data ready notifications. Used to call userCompleteCallback handler function. </td><td>Release interrupt number, for Client side only  </td></tr>
<tr>
<td><a class="el" href="structcy__stc__crypto__config__t.html#a52ff77b99e58e9f238f260a50740be7b">userCompleteCallback</a> </td><td>Client </td><td>User-defined callback for the Release interrupt handler; can be NULL </td><td>See Implementing Crypto Interrupts  </td></tr>
<tr>
<td><a class="el" href="structcy__stc__crypto__config__t.html#ab0c85bc368f569f5ded79957fb32b7a8">releaseNotifierConfig </a> </td><td>Client </td><td>IRQ handler settings for data ready notifications. This interrupt occurs when server completely processed all input data and released an IPC communication channel. </td><td>configuration for the interrupt  </td></tr>
<tr>
<td><a class="el" href="structcy__stc__crypto__config__t.html#a4130639046fb3a253bf8898f5dc23f7b">userGetDataHandler</a> </td><td>Server </td><td>User-defined function to override default interrupt handler; NULL = use default </td><td>ISR for the Notify interrupt  </td></tr>
<tr>
<td><a class="el" href="structcy__stc__crypto__config__t.html#abd4789ed2371b4b38395295401248b34">acquireNotifierConfig</a> </td><td>Server </td><td>IRQ handler settings for new request notifications. This interrupt occurs when client sent a new request for processing. </td><td>configuration for the interrupt  </td></tr>
<tr>
<td><a class="el" href="structcy__stc__crypto__config__t.html#a0edc56bcfa1323e9fbf2421afbec9f72">userErrorHandler</a> </td><td>Server </td><td>User-defined function to override default interrupt handler; NULL = use default </td><td>ISR for a server error  </td></tr>
<tr>
<td><a class="el" href="structcy__stc__crypto__config__t.html#a41313f24ce9075f5262938072669fea4">cryptoErrorIntrConfig</a> </td><td>Server </td><td>IRQ handler settings for hardware error events </td><td>configuration for the interrupt  </td></tr>
</table>
<h1><a class="anchor" id="group_crypto_server_init"></a>
Server Initialization</h1>
<p>Use a <a class="el" href="group__group__crypto__srv__functions.html#ga1b6e8094edd6fa456da67f4b31ab754b">Cy_Crypto_Server_Start</a> function. Provide the configuration parameters (<a class="el" href="structcy__stc__crypto__config__t.html" title="The Crypto configuration structure. ">cy_stc_crypto_config_t</a>) and a pointer to the server context (<a class="el" href="structcy__stc__crypto__server__context__t.html" title="The structure for storing the crypto server context. ">cy_stc_crypto_server_context_t</a>) that will be used to store all temporary data.</p>
<div class="fragment"><div class="line">    <span class="comment">/* Scenario: Configure Server and Client as follows:</span></div><div class="line"><span class="comment">     * Server:</span></div><div class="line"><span class="comment">     *  - IPC channel for communication: 9</span></div><div class="line"><span class="comment">     *  - IPC interrupt structure used for new request notifications: 1</span></div><div class="line"><span class="comment">     *  - Data request handler: default</span></div><div class="line"><span class="comment">     *  - Hardware errors handler: default</span></div><div class="line"><span class="comment">     * Client:</span></div><div class="line"><span class="comment">     *  - IPC channel for communication: 9</span></div><div class="line"><span class="comment">     *  - IPC interrupt structure used for data ready notifications: 2</span></div><div class="line"><span class="comment">     *  - Data Complete callback: not used</span></div><div class="line"><span class="comment">     */</span></div><div class="line"></div><div class="line"><span class="preprocessor">    #define MY_CHAN_CRYPTO         (uint32_t)(9u)    </span><span class="comment">/* IPC data channel for the Crypto */</span><span class="preprocessor"></span></div><div class="line"><span class="preprocessor">    #define MY_INTR_CRYPTO_SRV     (uint32_t)(1u)    </span><span class="comment">/* IPC interrupt structure for the Crypto server */</span><span class="preprocessor"></span></div><div class="line"><span class="preprocessor">    #define MY_INTR_CRYPTO_CLI     (uint32_t)(2u)    </span><span class="comment">/* IPC interrupt structure for the Crypto client */</span><span class="preprocessor"></span></div><div class="line"></div><div class="line"><span class="preprocessor">    #define MY_INTR_CRYPTO_SRV_MUX (IRQn_Type)(2u)   </span><span class="comment">/* CM0+ IPC interrupt mux number the Crypto server */</span><span class="preprocessor"></span></div><div class="line"><span class="preprocessor">    #define MY_INTR_CRYPTO_CLI_MUX (IRQn_Type)(3u)   </span><span class="comment">/* CM0+ IPC interrupt mux number the Crypto client */</span><span class="preprocessor"></span></div><div class="line"><span class="preprocessor">    #define MY_INTR_CRYPTO_ERR_MUX (IRQn_Type)(4u)   </span><span class="comment">/* CM0+ ERROR interrupt mux number the Crypto server */</span><span class="preprocessor"></span></div><div class="line"></div><div class="line">    <span class="keyword">const</span> <a class="code" href="structcy__stc__crypto__config__t.html">cy_stc_crypto_config_t</a> myCryptoConfig =</div><div class="line">    {</div><div class="line">        <span class="comment">/* .ipcChannel             */</span> MY_CHAN_CRYPTO,</div><div class="line">        <span class="comment">/* .acquireNotifierChannel */</span> MY_INTR_CRYPTO_SRV,</div><div class="line">        <span class="comment">/* .releaseNotifierChannel */</span> MY_INTR_CRYPTO_CLI,</div><div class="line"></div><div class="line">        <span class="comment">/* .releaseNotifierConfig */</span> {</div><div class="line"><span class="preprocessor">        #if (CY_CPU_CORTEX_M0P)</span></div><div class="line">            <span class="comment">/* .intrSrc            */</span> MY_INTR_CRYPTO_CLI_MUX,</div><div class="line">            <span class="comment">/* .cm0pSrc            */</span> cpuss_interrupts_ipc_2_IRQn, <span class="comment">/* depends on selected releaseNotifierChannel value */</span></div><div class="line"><span class="preprocessor">        #else</span></div><div class="line">            <span class="comment">/* .intrSrc            */</span> cpuss_interrupts_ipc_2_IRQn, <span class="comment">/* depends on selected releaseNotifierChannel value */</span></div><div class="line"><span class="preprocessor">        #endif</span></div><div class="line">            <span class="comment">/* .intrPriority       */</span> 2u,</div><div class="line">        },</div><div class="line"></div><div class="line">        <span class="comment">/* .userCompleteCallback   */</span> NULL,</div><div class="line">        <span class="comment">/* .userGetDataHandler     */</span> NULL,</div><div class="line">        <span class="comment">/* .userErrorHandler       */</span> NULL,</div><div class="line"></div><div class="line">        <span class="comment">/* .acquireNotifierConfig */</span> {</div><div class="line"><span class="preprocessor">        #if (CY_CPU_CORTEX_M0P)</span></div><div class="line">            <span class="comment">/* .intrSrc            */</span> MY_INTR_CRYPTO_SRV_MUX,      <span class="comment">/* to use with DeepSleep mode should be in DeepSleep capable muxer&#39;s range */</span></div><div class="line">            <span class="comment">/* .cm0pSrc            */</span> cpuss_interrupts_ipc_1_IRQn, <span class="comment">/* depends on selected acquireNotifierChannel value */</span></div><div class="line"><span class="preprocessor">        #else</span></div><div class="line">            <span class="comment">/* .intrSrc            */</span> cpuss_interrupts_ipc_1_IRQn, <span class="comment">/* depends on selected acquireNotifierChannel value */</span></div><div class="line"><span class="preprocessor">        #endif</span></div><div class="line">            <span class="comment">/* .intrPriority       */</span> 2u,</div><div class="line">        },</div><div class="line">        <span class="comment">/* .cryptoErrorIntrConfig */</span> {</div><div class="line"><span class="preprocessor">        #if (CY_CPU_CORTEX_M0P)</span></div><div class="line">            <span class="comment">/* .intrSrc            */</span> MY_INTR_CRYPTO_ERR_MUX,</div><div class="line">            <span class="comment">/* .cm0pSrc            */</span> cpuss_interrupt_crypto_IRQn,</div><div class="line"><span class="preprocessor">        #else</span></div><div class="line">            <span class="comment">/* .intrSrc            */</span> cpuss_interrupt_crypto_IRQn,</div><div class="line"><span class="preprocessor">        #endif</span></div><div class="line">            <span class="comment">/* .intrPriority       */</span> 2u,</div><div class="line">        }</div><div class="line">    };</div><div class="line"></div><div class="line">    <a class="code" href="structcy__stc__crypto__server__context__t.html">cy_stc_crypto_server_context_t</a>  myCryptoServerContext;</div><div class="line">    <a class="code" href="group__group__crypto__enums.html#ga3a65158da3dc5cb6aa016ae599542aad">cy_en_crypto_status_t</a>           cryptoStatus;</div><div class="line"></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__srv__functions.html#ga1b6e8094edd6fa456da67f4b31ab754b">Cy_Crypto_Server_Start</a>(&amp;myCryptoConfig, &amp;myCryptoServerContext);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div></div><!-- fragment --><p> Because the two cores operate asynchronously, ensure that server initialization is complete before initializing the client. There are several ways to do this:</p>
<ul>
<li>Use <a class="el" href="group__group__crypto__cli__functions.html#gac3fb202ea63ed0bec857424f8aac4b7e">Cy_Crypto_Sync</a> as a blocking call, before initializing the client.</li>
<li>Enable the CM4 core (<a class="el" href="group__group__system__config__cm4__functions.html#gac44c12fdb0562403fc055e4e8966b557">Cy_SysEnableCM4</a>) after Crypto Server Start executes successfully.</li>
<li>Check the return status from calls to <a class="el" href="group__group__crypto__cli__functions.html#ga79963cfa80b828a77a85bd8e144af2e1">Cy_Crypto_Init</a> or <a class="el" href="group__group__crypto__cli__functions.html#ga667e7a1cc511e30028e3c2848c17e26a">Cy_Crypto_Enable</a> to ensure <a class="el" href="group__group__crypto__enums.html#gga3a65158da3dc5cb6aa016ae599542aada15d5a5e1314e16c159b7d3fd6f3501b8">CY_CRYPTO_SUCCESS</a>.</li>
</ul>
<p>All crypto operations are asynchronous. To ensure that any crypto operation is complete and the result is valid, use <a class="el" href="group__group__crypto__cli__functions.html#gac3fb202ea63ed0bec857424f8aac4b7e">Cy_Crypto_Sync</a>. Use the <a class="el" href="group__group__crypto__cli__srv__macros.html#ga8c9dbbac988d88bc7b8ec861b9e18836">CY_CRYPTO_SYNC_NON_BLOCKING</a> parameter to check status. Use <a class="el" href="group__group__crypto__cli__srv__macros.html#ga7cad37b39669bf7ec2994103962c73ad">CY_CRYPTO_SYNC_BLOCKING</a> to wait for the operation to complete.</p>
<h1><a class="anchor" id="group_crypto_client_init"></a>
Client initialization</h1>
<p>Use <a class="el" href="group__group__crypto__cli__functions.html#ga79963cfa80b828a77a85bd8e144af2e1">Cy_Crypto_Init</a> to initialize the Crypto client with the configuration parameters (<a class="el" href="structcy__stc__crypto__config__t.html" title="The Crypto configuration structure. ">cy_stc_crypto_config_t</a>) and a pointer to the context (<a class="el" href="structcy__stc__crypto__context__t.html" title="The structure for storing the crypto client context. ">cy_stc_crypto_context_t</a>). Do not fill in the values for the context structure.</p>
<p>Then call <a class="el" href="group__group__crypto__cli__functions.html#ga667e7a1cc511e30028e3c2848c17e26a">Cy_Crypto_Enable</a> to enable the Crypto hardware IP block. After this, the Crypto driver is ready to execute crypto functions. These calls must be made on the client side. Firmware can implement the client on either core.</p>
<div class="fragment"><div class="line">    <span class="comment">/* Scenario: Configure Server and Client as follows:</span></div><div class="line"><span class="comment">     * Server:</span></div><div class="line"><span class="comment">     *  - IPC channel for communication: 9</span></div><div class="line"><span class="comment">     *  - IPC interrupt structure used for new request notifications: 1</span></div><div class="line"><span class="comment">     *  - Data request handler: default</span></div><div class="line"><span class="comment">     *  - Hardware errors handler: default</span></div><div class="line"><span class="comment">     * Client:</span></div><div class="line"><span class="comment">     *  - IPC channel for communication: 9</span></div><div class="line"><span class="comment">     *  - IPC interrupt structure used for data ready notifications: 2</span></div><div class="line"><span class="comment">     *  - Data Complete callback: not used</span></div><div class="line"><span class="comment">     */</span></div><div class="line"></div><div class="line"><span class="preprocessor">    #define MY_CHAN_CRYPTO         (uint32_t)(9u)    </span><span class="comment">/* IPC data channel for the Crypto */</span><span class="preprocessor"></span></div><div class="line"><span class="preprocessor">    #define MY_INTR_CRYPTO_SRV     (uint32_t)(1u)    </span><span class="comment">/* IPC interrupt structure for the Crypto server */</span><span class="preprocessor"></span></div><div class="line"><span class="preprocessor">    #define MY_INTR_CRYPTO_CLI     (uint32_t)(2u)    </span><span class="comment">/* IPC interrupt structure for the Crypto client */</span><span class="preprocessor"></span></div><div class="line"></div><div class="line"><span class="preprocessor">    #define MY_INTR_CRYPTO_SRV_MUX (IRQn_Type)(2u)   </span><span class="comment">/* CM0+ IPC interrupt mux number the Crypto server */</span><span class="preprocessor"></span></div><div class="line"><span class="preprocessor">    #define MY_INTR_CRYPTO_CLI_MUX (IRQn_Type)(3u)   </span><span class="comment">/* CM0+ IPC interrupt mux number the Crypto client */</span><span class="preprocessor"></span></div><div class="line"><span class="preprocessor">    #define MY_INTR_CRYPTO_ERR_MUX (IRQn_Type)(4u)   </span><span class="comment">/* CM0+ ERROR interrupt mux number the Crypto server */</span><span class="preprocessor"></span></div><div class="line"></div><div class="line">    <span class="keyword">const</span> <a class="code" href="structcy__stc__crypto__config__t.html">cy_stc_crypto_config_t</a> myCryptoConfig =</div><div class="line">    {</div><div class="line">        <span class="comment">/* .ipcChannel             */</span> MY_CHAN_CRYPTO,</div><div class="line">        <span class="comment">/* .acquireNotifierChannel */</span> MY_INTR_CRYPTO_SRV,</div><div class="line">        <span class="comment">/* .releaseNotifierChannel */</span> MY_INTR_CRYPTO_CLI,</div><div class="line"></div><div class="line">        <span class="comment">/* .releaseNotifierConfig */</span> {</div><div class="line"><span class="preprocessor">        #if (CY_CPU_CORTEX_M0P)</span></div><div class="line">            <span class="comment">/* .intrSrc            */</span> MY_INTR_CRYPTO_CLI_MUX,</div><div class="line">            <span class="comment">/* .cm0pSrc            */</span> cpuss_interrupts_ipc_2_IRQn, <span class="comment">/* depends on selected releaseNotifierChannel value */</span></div><div class="line"><span class="preprocessor">        #else</span></div><div class="line">            <span class="comment">/* .intrSrc            */</span> cpuss_interrupts_ipc_2_IRQn, <span class="comment">/* depends on selected releaseNotifierChannel value */</span></div><div class="line"><span class="preprocessor">        #endif</span></div><div class="line">            <span class="comment">/* .intrPriority       */</span> 2u,</div><div class="line">        },</div><div class="line"></div><div class="line">        <span class="comment">/* .userCompleteCallback   */</span> NULL,</div><div class="line">        <span class="comment">/* .userGetDataHandler     */</span> NULL,</div><div class="line">        <span class="comment">/* .userErrorHandler       */</span> NULL,</div><div class="line"></div><div class="line">        <span class="comment">/* .acquireNotifierConfig */</span> {</div><div class="line"><span class="preprocessor">        #if (CY_CPU_CORTEX_M0P)</span></div><div class="line">            <span class="comment">/* .intrSrc            */</span> MY_INTR_CRYPTO_SRV_MUX,      <span class="comment">/* to use with DeepSleep mode should be in DeepSleep capable muxer&#39;s range */</span></div><div class="line">            <span class="comment">/* .cm0pSrc            */</span> cpuss_interrupts_ipc_1_IRQn, <span class="comment">/* depends on selected acquireNotifierChannel value */</span></div><div class="line"><span class="preprocessor">        #else</span></div><div class="line">            <span class="comment">/* .intrSrc            */</span> cpuss_interrupts_ipc_1_IRQn, <span class="comment">/* depends on selected acquireNotifierChannel value */</span></div><div class="line"><span class="preprocessor">        #endif</span></div><div class="line">            <span class="comment">/* .intrPriority       */</span> 2u,</div><div class="line">        },</div><div class="line">        <span class="comment">/* .cryptoErrorIntrConfig */</span> {</div><div class="line"><span class="preprocessor">        #if (CY_CPU_CORTEX_M0P)</span></div><div class="line">            <span class="comment">/* .intrSrc            */</span> MY_INTR_CRYPTO_ERR_MUX,</div><div class="line">            <span class="comment">/* .cm0pSrc            */</span> cpuss_interrupt_crypto_IRQn,</div><div class="line"><span class="preprocessor">        #else</span></div><div class="line">            <span class="comment">/* .intrSrc            */</span> cpuss_interrupt_crypto_IRQn,</div><div class="line"><span class="preprocessor">        #endif</span></div><div class="line">            <span class="comment">/* .intrPriority       */</span> 2u,</div><div class="line">        }</div><div class="line">    };</div><div class="line"></div><div class="line">    <a class="code" href="structcy__stc__crypto__context__t.html">cy_stc_crypto_context_t</a>     myCryptoContext;</div><div class="line">    <a class="code" href="group__group__crypto__enums.html#ga3a65158da3dc5cb6aa016ae599542aad">cy_en_crypto_status_t</a>       cryptoStatus;</div><div class="line"></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#ga79963cfa80b828a77a85bd8e144af2e1">Cy_Crypto_Init</a>(&amp;myCryptoConfig, &amp;myCryptoContext);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#ga667e7a1cc511e30028e3c2848c17e26a">Cy_Crypto_Enable</a>();</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div></div><!-- fragment --> <h1><a class="anchor" id="group_crypto_common_use_cases"></a>
Common Use Cases</h1>
<h2><a class="anchor" id="group_crypto_Use_CRC"></a>
CRC Calculation</h2>
<p>To calculate CRC of a data image:</p><ul>
<li>Use <a class="el" href="group__group__crypto__cli__functions.html#ga833ab5adcd2c03da11cc883eb706ff20">Cy_Crypto_Crc_Init</a> to set parameters for selected CRC mode,</li>
<li>Call <a class="el" href="group__group__crypto__cli__functions.html#ga3c78c11d34fa63664275a7df5b35062c">Cy_Crypto_Crc_Run</a> to calculate CRC for a data image.</li>
</ul>
<p>Code example: </p><div class="fragment"><div class="line">    <span class="comment">/* CRC parameters for some CRC algorithms:</span></div><div class="line"><span class="comment">    +---------------------+-----+------------+------------+------+------+-----+------------+------------+</span></div><div class="line"><span class="comment">    | CRC algorithm Name  | CRC |  Polynom   |   Initial  | Data | Data | Rem |  Remainder |  Expected  |</span></div><div class="line"><span class="comment">    |                     | len |            |    seed    | REV  | XOR  | REV |    XOR     |    CRC     |</span></div><div class="line"><span class="comment">    | ------------------- | --- | ---------- |----------- | ---- | ---- | --- | ---------- | ---------- |</span></div><div class="line"><span class="comment">    | CRC-6  / CDMA2000-A |  6  |    0x27    |    0x3F    |   0  |   0  |  0  |    0x00    |    0x0D    |</span></div><div class="line"><span class="comment">    | CRC-6  / CDMA2000-B |  6  |    0x07    |    0x3F    |   0  |   0  |  0  |    0x00    |    0x3B    |</span></div><div class="line"><span class="comment">    | CRC-6  / DARC       |  6  |    0x19    |    0x00    |   1  |   0  |  1  |    0x00    |    0x26    |</span></div><div class="line"><span class="comment">    | CRC-6  / ITU        |  6  |    0x03    |    0x00    |   1  |   0  |  1  |    0x00    |    0x06    |</span></div><div class="line"><span class="comment">    | CRC-8  / ITU        |  8  |    0x07    |    0x00    |   0  |   0  |  0  |    0x55    |    0xA1    |</span></div><div class="line"><span class="comment">    | CRC-8  / MAXIM      |  8  |    0x31    |    0x00    |   1  |   0  |  1  |    0x00    |    0xA1    |</span></div><div class="line"><span class="comment">    | CRC-8  / ROHC       |  8  |    0x07    |    0xFF    |   1  |   0  |  1  |    0x00    |    0xD0    |</span></div><div class="line"><span class="comment">    | CRC-8  / WCDMA      |  8  |    0x9B    |    0x00    |   1  |   0  |  1  |    0x00    |    0x25    |</span></div><div class="line"><span class="comment">    | CRC-16 / CCITT-0    | 16  |   0x1021   |   0xFFFF   |   0  |   0  |  0  |   0x0000   |   0x29B1   |</span></div><div class="line"><span class="comment">    | CRC-16 / CDMA2000   | 16  |   0xC867   |   0xFFFF   |   0  |   0  |  0  |   0x0000   |   0x4C06   |</span></div><div class="line"><span class="comment">    | CRC-32              | 32  | 0x04C11DB7 | 0xFFFFFFFF |   1  |   0  |  1  | 0xFFFFFFFF | 0xCBF43926 |</span></div><div class="line"><span class="comment">    | CRC-32 / BZIP2      | 32  | 0x04C11DB7 | 0xFFFFFFFF |   0  |   0  |  0  | 0xFFFFFFFF | 0xFC891918 |</span></div><div class="line"><span class="comment">    +---------------------+-----+------------+------------+------+------+-----+------------+------------+</span></div><div class="line"><span class="comment">    */</span></div><div class="line"></div><div class="line">    <span class="comment">/* Use &quot;CRC-16/CCITT-0&quot; calculation */</span></div><div class="line"><span class="preprocessor">    #define CRC_BITLEN          (16u)</span></div><div class="line"><span class="preprocessor">    #define CRC_POLYNOMIAL      (0x1021u)</span></div><div class="line"><span class="preprocessor">    #define CRC_LFSR_SEED       (0xffffu)</span></div><div class="line"><span class="preprocessor">    #define CRC_DATA_REVERSE    (0u)</span></div><div class="line"><span class="preprocessor">    #define CRC_DATA_XOR        (0u)</span></div><div class="line"><span class="preprocessor">    #define CRC_REM_REVERSE     (0u)</span></div><div class="line"><span class="preprocessor">    #define CRC_REM_XOR         (0x0000u)</span></div><div class="line"></div><div class="line">    CY_ALIGN(4) uint8_t         message[9] = &quot;123456789&quot;;</div><div class="line">    CY_ALIGN(4) uint32_t        calculatedCrc = 0;</div><div class="line"></div><div class="line">    <a class="code" href="structcy__stc__crypto__context__crc__t.html">cy_stc_crypto_context_crc_t</a> cryptoCrcContext;</div><div class="line">    <a class="code" href="group__group__crypto__enums.html#ga3a65158da3dc5cb6aa016ae599542aad">cy_en_crypto_status_t</a>       cryptoStatus;</div><div class="line"></div><div class="line">    <span class="comment">/* Initialization Crypto operation */</span></div><div class="line">    <span class="comment">/* Note: Polynomial and Remainder XOR values are always MSB aligned. */</span></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#ga833ab5adcd2c03da11cc883eb706ff20">Cy_Crypto_Crc_Init</a>((CRC_POLYNOMIAL &lt;&lt; (32 - CRC_BITLEN)),</div><div class="line">                                CRC_DATA_REVERSE,</div><div class="line">                                CRC_DATA_XOR,</div><div class="line">                                CRC_REM_REVERSE,</div><div class="line">                                (CRC_REM_XOR &lt;&lt; (32 - CRC_BITLEN)),</div><div class="line">                                &amp;cryptoCrcContext);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div><div class="line">    <span class="comment">/* Wait crypto become available */</span></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#gac3fb202ea63ed0bec857424f8aac4b7e">Cy_Crypto_Sync</a>(<a class="code" href="group__group__crypto__cli__srv__macros.html#ga7cad37b39669bf7ec2994103962c73ad">CY_CRYPTO_SYNC_BLOCKING</a>);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div><div class="line">    <span class="comment">/* Calculate CRC */</span></div><div class="line">    <span class="comment">/* Note: Initial seed value is always MSB aligned. */</span></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#ga3c78c11d34fa63664275a7df5b35062c">Cy_Crypto_Crc_Run</a>((<span class="keywordtype">void</span>*)message,</div><div class="line">                                sizeof(message),</div><div class="line">                                &amp;calculatedCrc,</div><div class="line">                                (uint32_t)(CRC_LFSR_SEED &lt;&lt; (32u - CRC_BITLEN)),</div><div class="line">                                &amp;cryptoCrcContext);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div><div class="line">    <span class="comment">/* Wait crypto become available */</span></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#gac3fb202ea63ed0bec857424f8aac4b7e">Cy_Crypto_Sync</a>(CY_CRYPTO_SYNC_BLOCKING);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div><div class="line">    <span class="comment">/* Note: Calculated CRC value is MSB aligned and should be shifted WHEN CRC_DATA_REVERSE is zero. */</span></div><div class="line">    if (CRC_DATA_REVERSE == 0u)</div><div class="line">    {</div><div class="line">        calculatedCrc = calculatedCrc &gt;&gt; (32 - CRC_BITLEN);</div><div class="line">    }</div><div class="line"></div></div><!-- fragment --> <h2><a class="anchor" id="group_crypto_Use_PRNG"></a>
Pseudo Random Number Generation</h2>
<p>To generate a pseudo random number:</p><ul>
<li>Use <a class="el" href="group__group__crypto__cli__functions.html#gace7c0bf28d501bba93e6ec2a2bd9a5ff">Cy_Crypto_Prng_Init</a> to set required parameters,</li>
<li>Call <a class="el" href="group__group__crypto__cli__functions.html#ga093ac7a4aa184e35f840363b7e2e55c7">Cy_Crypto_Prng_Generate</a>.</li>
</ul>
<p>Code example: </p><div class="fragment"><div class="line"></div><div class="line">    <span class="comment">/* Initialization seed values for Pseudo Random Generator */</span></div><div class="line"><span class="preprocessor">    #define LFSR32_INITSTATE      (0xd8959bc9)</span></div><div class="line"><span class="preprocessor">    #define LFSR31_INITSTATE      (0x2bb911f8)</span></div><div class="line"><span class="preprocessor">    #define LFSR29_INITSTATE      (0x060c31b7)</span></div><div class="line"></div><div class="line"><span class="preprocessor">    #define MAX_PRNG_VALUE        (255UL)</span></div><div class="line"></div><div class="line">    <span class="comment">/* Generated Random Number */</span></div><div class="line">    uint32_t rndNum = 0;</div><div class="line"></div><div class="line">    <a class="code" href="structcy__stc__crypto__context__prng__t.html">cy_stc_crypto_context_prng_t</a>  cryptoPrngContext;</div><div class="line">    <a class="code" href="group__group__crypto__enums.html#ga3a65158da3dc5cb6aa016ae599542aad">cy_en_crypto_status_t</a>         cryptoStatus;</div><div class="line"></div><div class="line">    <span class="comment">/* Initialize Pseudo Random Generator in Crypto Driver */</span></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#gace7c0bf28d501bba93e6ec2a2bd9a5ff">Cy_Crypto_Prng_Init</a>(</div><div class="line">                        LFSR32_INITSTATE,</div><div class="line">                        LFSR31_INITSTATE,</div><div class="line">                        LFSR29_INITSTATE, &amp;cryptoPrngContext);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div><div class="line">    <span class="comment">/* Generate Pseudo Random number into rndNum variable */</span></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#ga093ac7a4aa184e35f840363b7e2e55c7">Cy_Crypto_Prng_Generate</a>(MAX_PRNG_VALUE, &amp;rndNum, &amp;cryptoPrngContext);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div><div class="line">    <span class="comment">/* Wait crypto become available */</span></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#gac3fb202ea63ed0bec857424f8aac4b7e">Cy_Crypto_Sync</a>(<a class="code" href="group__group__crypto__cli__srv__macros.html#ga7cad37b39669bf7ec2994103962c73ad">CY_CRYPTO_SYNC_BLOCKING</a>);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div></div><!-- fragment --> <h2><a class="anchor" id="group_crypto_Use_TRNG"></a>
True Random Number Generation</h2>
<p>To generate a true random number:</p><ul>
<li>Call <a class="el" href="group__group__crypto__cli__functions.html#ga69061dfb8a8ccd707edf8151e1427987">Cy_Crypto_Trng_Generate</a> with needed parameters.</li>
</ul>
<p>Code example: </p><div class="fragment"><div class="line"></div><div class="line">    <span class="comment">/* Initialization polynomial values for True Random Generator.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">        Polynomial for programmable Galois ring oscillator.</span></div><div class="line"><span class="comment">        The polynomial is represented WITHOUT the high order bit (this bit is always assumed &#39;1&#39;).</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">        GARO 31 bit polynomial (0x04c1:1db7) = x31 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">        Polynomial for programmable Fibonacci ring oscillator.</span></div><div class="line"><span class="comment">        The polynomial is represented WITHOUT the high order bit (this bit is always assumed &#39;1&#39;).</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">        FIRO 31 bit polynomial (0x04c1:1db7) = x31 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1</span></div><div class="line"><span class="comment">    */</span></div><div class="line"><span class="preprocessor">    #define GARO31_INITSTATE      (0x04c11db7)</span></div><div class="line"><span class="preprocessor">    #define FIRO31_INITSTATE      (0x04c11db7)</span></div><div class="line"></div><div class="line"><span class="preprocessor">    #define MAX_TRNG_BIT_SIZE     (32UL)</span></div><div class="line"></div><div class="line">    <span class="comment">/* Generated Random Number */</span></div><div class="line">    uint32_t rndNum = 0;</div><div class="line"></div><div class="line">    <a class="code" href="structcy__stc__crypto__context__trng__t.html">cy_stc_crypto_context_trng_t</a>  cryptoTrngContext;</div><div class="line">    <a class="code" href="group__group__crypto__enums.html#ga3a65158da3dc5cb6aa016ae599542aad">cy_en_crypto_status_t</a>         cryptoStatus;</div><div class="line"></div><div class="line">    <span class="comment">/* Generate True Random number */</span></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#ga69061dfb8a8ccd707edf8151e1427987">Cy_Crypto_Trng_Generate</a>(</div><div class="line">                        GARO31_INITSTATE,</div><div class="line">                        FIRO31_INITSTATE,</div><div class="line">                        MAX_TRNG_BIT_SIZE,</div><div class="line">                        &amp;rndNum, &amp;cryptoTrngContext);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div><div class="line">    <span class="comment">/* Wait crypto become available */</span></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#gac3fb202ea63ed0bec857424f8aac4b7e">Cy_Crypto_Sync</a>(<a class="code" href="group__group__crypto__cli__srv__macros.html#ga7cad37b39669bf7ec2994103962c73ad">CY_CRYPTO_SYNC_BLOCKING</a>);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div></div><!-- fragment --> <h2><a class="anchor" id="group_crypto_Use_DES"></a>
DES encryption</h2>
<p>To encrypt a message using the DES algorithm:</p><ul>
<li>Place DES key into an array,</li>
<li>Call <a class="el" href="group__group__crypto__cli__functions.html#gab5ab6f272d15ebb2fb14000530b6d29a">Cy_Crypto_Des_Run</a> with required parameters, including the key array</li>
</ul>
<p>Code example: </p><div class="fragment"><div class="line">    <span class="comment">/* Note: all keys are placed into the one keys array. */</span></div><div class="line"></div><div class="line"><span class="preprocessor">    #define STRING_LENGTH  8</span></div><div class="line">    CY_ALIGN(4) uint8_t msgString[STRING_LENGTH] = &quot;Crypto!&quot;;</div><div class="line">    CY_ALIGN(4) uint8_t encString[STRING_LENGTH];</div><div class="line"></div><div class="line">    <span class="preprocessor">#define KEY1 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77</span></div><div class="line"></div><div class="line">    CY_ALIGN(4) uint8_t desKey[] = { KEY1 };</div><div class="line"></div><div class="line">    <a class="code" href="structcy__stc__crypto__context__des__t.html">cy_stc_crypto_context_des_t</a> cryptoDesContext;</div><div class="line">    <a class="code" href="group__group__crypto__enums.html#ga3a65158da3dc5cb6aa016ae599542aad">cy_en_crypto_status_t</a>       cryptoStatus;</div><div class="line"></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#gab5ab6f272d15ebb2fb14000530b6d29a">Cy_Crypto_Des_Run</a> ( <a class="code" href="group__group__crypto__enums.html#ggae040fb530d4d110976bedfcdb7c8f09ca4b95ef1e3f73771b0c6a376c6d43e16d">CY_CRYPTO_ENCRYPT</a>,</div><div class="line">                                      (uint32_t *)desKey,    <span class="comment">/* Pointer to key */</span></div><div class="line">                                      (uint32_t *)encString,  <span class="comment">/* Destination string */</span></div><div class="line">                                      (uint32_t *)msgString,  <span class="comment">/* Source String */</span></div><div class="line">                                      &amp;cryptoDesContext );</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div><div class="line">    <span class="comment">/* Wait crypto become available */</span></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#gac3fb202ea63ed0bec857424f8aac4b7e">Cy_Crypto_Sync</a>(<a class="code" href="group__group__crypto__cli__srv__macros.html#ga7cad37b39669bf7ec2994103962c73ad">CY_CRYPTO_SYNC_BLOCKING</a>);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div></div><!-- fragment --> <h2><a class="anchor" id="group_crypto_Use_TDES"></a>
TDES encryption</h2>
<p>To encrypt a message using the TDES algorithm:</p><ul>
<li>Place 3 DES keys into a solid array,</li>
<li>Call <a class="el" href="group__group__crypto__cli__functions.html#ga86c02f38711df37a1ca8f9b505ad5f2c">Cy_Crypto_Tdes_Run</a> with required parameters, including the array of keys</li>
</ul>
<p>Code example: </p><div class="fragment"><div class="line">    <span class="comment">/* Note: all keys are placed into the one keys array. */</span></div><div class="line"></div><div class="line"><span class="preprocessor">    #define STRING_LENGTH  8</span></div><div class="line">    CY_ALIGN(4) uint8_t msgString[STRING_LENGTH] = &quot;Crypto!&quot;;</div><div class="line">    CY_ALIGN(4) uint8_t encString[STRING_LENGTH];</div><div class="line"></div><div class="line">    <span class="preprocessor">#define KEY1 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77</span></div><div class="line"><span class="preprocessor">    #define KEY2 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF</span></div><div class="line"><span class="preprocessor">    #define KEY3 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08</span></div><div class="line"></div><div class="line">    CY_ALIGN(4) uint8_t tdesKey[] = { KEY1, KEY2, KEY3 };</div><div class="line"></div><div class="line">    <a class="code" href="structcy__stc__crypto__context__des__t.html">cy_stc_crypto_context_des_t</a> cryptoDesContext;</div><div class="line">    <a class="code" href="group__group__crypto__enums.html#ga3a65158da3dc5cb6aa016ae599542aad">cy_en_crypto_status_t</a>       cryptoStatus;</div><div class="line"></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#ga86c02f38711df37a1ca8f9b505ad5f2c">Cy_Crypto_Tdes_Run</a> ( <a class="code" href="group__group__crypto__enums.html#ggae040fb530d4d110976bedfcdb7c8f09ca4b95ef1e3f73771b0c6a376c6d43e16d">CY_CRYPTO_ENCRYPT</a>,</div><div class="line">                                      (uint32_t *)tdesKey,    <span class="comment">/* Pointer to keys */</span></div><div class="line">                                      (uint32_t *)encString,  <span class="comment">/* Destination string */</span></div><div class="line">                                      (uint32_t *)msgString,  <span class="comment">/* Source String */</span></div><div class="line">                                      &amp;cryptoDesContext );</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div><div class="line">    <span class="comment">/* Wait crypto become available */</span></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#gac3fb202ea63ed0bec857424f8aac4b7e">Cy_Crypto_Sync</a>(<a class="code" href="group__group__crypto__cli__srv__macros.html#ga7cad37b39669bf7ec2994103962c73ad">CY_CRYPTO_SYNC_BLOCKING</a>);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div></div><!-- fragment --> <h2><a class="anchor" id="group_crypto_Use_AES"></a>
AES encryption</h2>
<p>The Crypto driver provides a four AES encryption algorithms (ECB, CBC, CFB and CTR) that are used similarly.</p>
<p>To encrypt a message using AES ECB algorithm (as example):</p><ul>
<li>Place AES key into array of appropriate size</li>
<li>Use <a class="el" href="group__group__crypto__cli__functions.html#gae157d02a1be9a43e944337dd816eb618">Cy_Crypto_Aes_Init</a> to configure the operation</li>
<li>Call <a class="el" href="group__group__crypto__cli__functions.html#gaab0cf71455d23900d5d9b2606dd165c7">Cy_Crypto_Aes_Ecb_Run</a> (<a class="el" href="group__group__crypto__cli__functions.html#gaa392c5512b5b1dd8809563e3a7becae3">Cy_Crypto_Aes_Cbc_Run</a>, <a class="el" href="group__group__crypto__cli__functions.html#ga5d7cf59db1c7cb8ff970998733f0f9c0">Cy_Crypto_Aes_Cfb_Run</a> or <a class="el" href="group__group__crypto__cli__functions.html#gaaccdf2614546b6c5cea2fcf18a456c28">Cy_Crypto_Aes_Ctr_Run</a>) with appropriate parameters to make an operation</li>
</ul>
<p>Code example: </p><div class="fragment"><div class="line"></div><div class="line">    <span class="comment">/* All data arrays should be 4-byte aligned */</span></div><div class="line">    CY_ALIGN(4) uint8_t aesKey[<a class="code" href="group__group__crypto__cli__srv__macros.html#ga0170aa17289178203dcc2114a31c400e">CY_CRYPTO_AES_128_KEY_SIZE</a>] = {</div><div class="line">        0x2Bu, 0x7Eu, 0x15u, 0x16u, 0x28u, 0xAEu, 0xD2u, 0xA6u,</div><div class="line">        0xABu, 0xF7u, 0x15u, 0x88u, 0x09u, 0xCFu, 0x4Fu, 0x3Cu</div><div class="line">    };</div><div class="line"></div><div class="line">    CY_ALIGN(4) uint8_t aesEcbPlainText[<a class="code" href="group__group__crypto__cli__srv__macros.html#gab966285a569cc381f21ca7ebb9918128">CY_CRYPTO_AES_BLOCK_SIZE</a>]  = {</div><div class="line">        0x6Bu, 0xC0u, 0xBCu, 0xE1u, 0x2Au, 0x45u, 0x99u, 0x91u,</div><div class="line">        0xE1u, 0x34u, 0x74u, 0x1Au, 0x7Fu, 0x9Eu, 0x19u, 0x25u</div><div class="line">    };</div><div class="line"></div><div class="line">    CY_ALIGN(4) uint8_t aesEcbCipherText[<a class="code" href="group__group__crypto__cli__srv__macros.html#gab966285a569cc381f21ca7ebb9918128">CY_CRYPTO_AES_BLOCK_SIZE</a>] = {0};</div><div class="line"></div><div class="line">    <a class="code" href="structcy__stc__crypto__context__aes__t.html">cy_stc_crypto_context_aes_t</a>   cryptoAesContext;</div><div class="line">    <a class="code" href="group__group__crypto__enums.html#ga3a65158da3dc5cb6aa016ae599542aad">cy_en_crypto_status_t</a>         cryptoStatus;</div><div class="line"></div><div class="line">    <span class="comment">/* Initialize Crypto AES functionality  */</span></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#gae157d02a1be9a43e944337dd816eb618">Cy_Crypto_Aes_Init</a>(</div><div class="line">                        (uint32_t *)aesKey,</div><div class="line">                        <a class="code" href="group__group__crypto__enums.html#gga5402841d4798c0a82d41d8433c92b62fa1d7e508252e541450df0eb37f4c0bf6e">CY_CRYPTO_KEY_AES_128</a>,</div><div class="line">                        &amp;cryptoAesContext);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div><div class="line">    <span class="comment">/* Wait crypto become available */</span></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#gac3fb202ea63ed0bec857424f8aac4b7e">Cy_Crypto_Sync</a>(<a class="code" href="group__group__crypto__cli__srv__macros.html#ga7cad37b39669bf7ec2994103962c73ad">CY_CRYPTO_SYNC_BLOCKING</a>);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div><div class="line">    <span class="comment">/* Encrypt one block (16Bytes) by AES128 */</span></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#gaab0cf71455d23900d5d9b2606dd165c7">Cy_Crypto_Aes_Ecb_Run</a>(</div><div class="line">                        <a class="code" href="group__group__crypto__enums.html#ggae040fb530d4d110976bedfcdb7c8f09ca4b95ef1e3f73771b0c6a376c6d43e16d">CY_CRYPTO_ENCRYPT</a>,</div><div class="line">                        (uint32_t*)aesEcbCipherText,</div><div class="line">                        (uint32_t*)aesEcbPlainText,</div><div class="line">                        &amp;cryptoAesContext);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div><div class="line">    <span class="comment">/* Wait crypto become available */</span></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#gac3fb202ea63ed0bec857424f8aac4b7e">Cy_Crypto_Sync</a>(<a class="code" href="group__group__crypto__cli__srv__macros.html#ga7cad37b39669bf7ec2994103962c73ad">CY_CRYPTO_SYNC_BLOCKING</a>);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div></div><!-- fragment --> <h2><a class="anchor" id="group_crypto_Use_SHA"></a>
SHA digest calculation</h2>
<p>To calculate a SHA digest of a message:</p><ul>
<li>Call <a class="el" href="group__group__crypto__cli__functions.html#ga81fe41f71b97c14e6a4aefcaa78e3378">Cy_Crypto_Sha_Run</a> with appropriate parameters to make an operation</li>
</ul>
<p>Code example: </p><div class="fragment"><div class="line"></div><div class="line">    <span class="comment">/* All data arrays should be 4-byte aligned */</span></div><div class="line">    <span class="comment">/* Message is: &quot;abc&quot; */</span></div><div class="line">    CY_ALIGN(4) uint8_t sha256PlainText_1[3]  = &quot;abc&quot;;</div><div class="line"></div><div class="line">    <span class="comment">/* Calculated SHA-256 digest */</span></div><div class="line">    CY_ALIGN(4) uint8_t sha256Digest[<a class="code" href="group__group__crypto__cli__srv__macros.html#ga82ff1a7671e4f0cf2026cbda5ef7e12a">CY_CRYPTO_SHA256_DIGEST_SIZE</a>] = {0};</div><div class="line"></div><div class="line">    <a class="code" href="structcy__stc__crypto__context__sha__t.html">cy_stc_crypto_context_sha_t</a>   cryptoShaContext;</div><div class="line">    <a class="code" href="group__group__crypto__enums.html#ga3a65158da3dc5cb6aa016ae599542aad">cy_en_crypto_status_t</a>         cryptoStatus;</div><div class="line"></div><div class="line">    <span class="comment">/* Hash the message by SHA256 */</span></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#ga81fe41f71b97c14e6a4aefcaa78e3378">Cy_Crypto_Sha_Run</a>(</div><div class="line">                        (uint32_t *)sha256PlainText_1,</div><div class="line">                        <span class="keyword">sizeof</span>(sha256PlainText_1),</div><div class="line">                        (uint32_t *)sha256Digest,</div><div class="line">                        <a class="code" href="group__group__crypto__enums.html#gga66ead9efce36e261e978cad722bf2dbba2212390919051b39d22d567c508c6d1f">CY_CRYPTO_MODE_SHA256</a>,</div><div class="line">                        &amp;cryptoShaContext);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div><div class="line">    <span class="comment">/* Wait crypto become available */</span></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#gac3fb202ea63ed0bec857424f8aac4b7e">Cy_Crypto_Sync</a>(<a class="code" href="group__group__crypto__cli__srv__macros.html#ga7cad37b39669bf7ec2994103962c73ad">CY_CRYPTO_SYNC_BLOCKING</a>);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div></div><!-- fragment --> <h2><a class="anchor" id="group_crypto_Use_CMAC"></a>
CMAC calculation</h2>
<p>To calculate CMAC of a message:</p><ul>
<li>Place AES key into array of appropriate size</li>
<li>Use <a class="el" href="group__group__crypto__cli__functions.html#gae157d02a1be9a43e944337dd816eb618">Cy_Crypto_Aes_Init</a> to configure the operation</li>
<li>Call <a class="el" href="group__group__crypto__cli__functions.html#gaab0cf71455d23900d5d9b2606dd165c7">Cy_Crypto_Aes_Ecb_Run</a> with appropriate parameters to make an operation</li>
</ul>
<p>Code example: </p><div class="fragment"><div class="line"></div><div class="line">    <span class="comment">/* All data arrays should be 4-byte aligned */</span></div><div class="line">    CY_ALIGN(4) uint8_t cmacKey[<a class="code" href="group__group__crypto__cli__srv__macros.html#ga0b49d7f139227541dbc20bcd2a1867a4">CY_CRYPTO_AES_256_KEY_SIZE</a>] =</div><div class="line">    {</div><div class="line">        0x60u, 0x3Du, 0xEBu, 0x10u, 0x15u, 0xCAu, 0x71u, 0xBEu,</div><div class="line">        0x2Bu, 0x73u, 0xAEu, 0xF0u, 0x85u, 0x7Du, 0x77u, 0x81u,</div><div class="line">        0x1Fu, 0x35u, 0x2Cu, 0x07u, 0x3Bu, 0x61u, 0x08u, 0xD7u,</div><div class="line">        0x2Du, 0x98u, 0x10u, 0xA3u, 0x09u, 0x14u, 0xDFu, 0xF4u</div><div class="line">    };</div><div class="line"></div><div class="line">    CY_ALIGN(4) uint8_t cmac256PlainText[16]  =</div><div class="line">    {</div><div class="line">        0x6Bu, 0xC1u, 0xBEu, 0xE2u, 0x2Eu, 0x40u, 0x9Fu, 0x96u,</div><div class="line">        0xE9u, 0x3Du, 0x7Eu, 0x11u, 0x73u, 0x93u, 0x17u, 0x2Au</div><div class="line">    };</div><div class="line"></div><div class="line">    <span class="comment">/* Calculated CMAC */</span></div><div class="line">    CY_ALIGN(4) uint8_t cmac[<a class="code" href="group__group__crypto__cli__srv__macros.html#gab966285a569cc381f21ca7ebb9918128">CY_CRYPTO_AES_BLOCK_SIZE</a>] = {0};</div><div class="line"></div><div class="line">    <a class="code" href="structcy__stc__crypto__context__aes__t.html">cy_stc_crypto_context_aes_t</a>   cryptoAesContext;</div><div class="line">    <a class="code" href="group__group__crypto__enums.html#ga3a65158da3dc5cb6aa016ae599542aad">cy_en_crypto_status_t</a>         cryptoStatus;</div><div class="line"></div><div class="line">    <span class="comment">/* CMAC from the text message using AES-256 */</span></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#gadce7e0725bf4da6b0a597e60a615f5f8">Cy_Crypto_Aes_Cmac_Run</a>(</div><div class="line">                        (uint32_t *)cmac256PlainText,</div><div class="line">                        <span class="keyword">sizeof</span>(cmac256PlainText),</div><div class="line">                        (uint32_t *)cmacKey,</div><div class="line">                        <a class="code" href="group__group__crypto__enums.html#gga5402841d4798c0a82d41d8433c92b62fa3b323f55c81fca9b412fea5ed28bcb30">CY_CRYPTO_KEY_AES_256</a>,</div><div class="line">                        (uint32_t *)cmac,</div><div class="line">                        &amp;cryptoAesContext);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div><div class="line">    <span class="comment">/* Wait crypto become available */</span></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#gac3fb202ea63ed0bec857424f8aac4b7e">Cy_Crypto_Sync</a>(<a class="code" href="group__group__crypto__cli__srv__macros.html#ga7cad37b39669bf7ec2994103962c73ad">CY_CRYPTO_SYNC_BLOCKING</a>);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div></div><!-- fragment --> <h2><a class="anchor" id="group_crypto_Use_HMAC"></a>
HMAC calculation</h2>
<p>To calculate HMAC of a message:</p><ul>
<li>Place HMAC key into array of appropriate size</li>
<li>Call <a class="el" href="group__group__crypto__cli__functions.html#ga00f0ec4cac3b873b30ac5c4793f3c1d4">Cy_Crypto_Hmac_Run</a> with appropriate parameters to make an operation</li>
</ul>
<p>Code example: </p><div class="fragment"><div class="line"></div><div class="line">    <span class="comment">/* All data arrays should be 4-byte aligned */</span></div><div class="line">    CY_ALIGN(4) uint8_t hmac256Key[32] =</div><div class="line">    {</div><div class="line">        0x00u, 0x01u, 0x02u, 0x03u, 0x04u, 0x05u, 0x06u, 0x07u,</div><div class="line">        0x08u, 0x09u, 0x0Au, 0x0Bu, 0x0Cu, 0x0Du, 0x0Eu, 0x0Fu,</div><div class="line">        0x10u, 0x11u, 0x12u, 0x13u, 0x14u, 0x15u, 0x16u, 0x17u,</div><div class="line">        0x18u, 0x19u, 0x1Au, 0x1Bu, 0x1Cu, 0x1Du, 0x1Eu, 0x1Fu</div><div class="line">    };</div><div class="line"></div><div class="line">    CY_ALIGN(4) uint8_t hmac256PlainText[34]  =</div><div class="line">    {</div><div class="line">        0x53u, 0x61u,</div><div class="line">        0x6Du, 0x70u, 0x6Cu, 0x65u, 0x20u, 0x6Du, 0x65u, 0x73u,</div><div class="line">        0x73u, 0x61u, 0x67u, 0x65u, 0x20u, 0x66u, 0x6Fu, 0x72u,</div><div class="line">        0x20u, 0x6Bu, 0x65u, 0x79u, 0x6Cu, 0x65u, 0x6Eu, 0x3Cu,</div><div class="line">        0x62u, 0x6Cu, 0x6Fu, 0x63u, 0x6Bu, 0x6Cu, 0x65u, 0x6Eu</div><div class="line">    };</div><div class="line"></div><div class="line">    <span class="comment">/* Calculated HMAC */</span></div><div class="line">    CY_ALIGN(4) uint8_t hmac256[<a class="code" href="group__group__crypto__cli__srv__macros.html#ga82ff1a7671e4f0cf2026cbda5ef7e12a">CY_CRYPTO_SHA256_DIGEST_SIZE</a>] = {0};</div><div class="line"></div><div class="line">    <a class="code" href="structcy__stc__crypto__context__sha__t.html">cy_stc_crypto_context_sha_t</a>   cryptoShaContext;</div><div class="line">    <a class="code" href="group__group__crypto__enums.html#ga3a65158da3dc5cb6aa016ae599542aad">cy_en_crypto_status_t</a>         cryptoStatus;</div><div class="line"></div><div class="line">    <span class="comment">/* HMAC from the text message using SHA256 */</span></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#ga00f0ec4cac3b873b30ac5c4793f3c1d4">Cy_Crypto_Hmac_Run</a>(</div><div class="line">                        (uint32_t *)hmac256,</div><div class="line">                        (uint32_t *)hmac256PlainText,</div><div class="line">                        <span class="keyword">sizeof</span>(hmac256PlainText),</div><div class="line">                        (uint32_t *)hmac256Key,</div><div class="line">                        <span class="keyword">sizeof</span>(hmac256Key),</div><div class="line">                        <a class="code" href="group__group__crypto__enums.html#gga66ead9efce36e261e978cad722bf2dbba2212390919051b39d22d567c508c6d1f">CY_CRYPTO_MODE_SHA256</a>,</div><div class="line">                        &amp;cryptoShaContext);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div><div class="line">    <span class="comment">/* Wait crypto become available */</span></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#gac3fb202ea63ed0bec857424f8aac4b7e">Cy_Crypto_Sync</a>(<a class="code" href="group__group__crypto__cli__srv__macros.html#ga7cad37b39669bf7ec2994103962c73ad">CY_CRYPTO_SYNC_BLOCKING</a>);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div></div><!-- fragment --> <h2><a class="anchor" id="group_crypto_Use_RSA_VER"></a>
RSA signature verification</h2>
<p>To verify the RSA signature of the data image:</p><ul>
<li>Fill RSA public key structure by RSA public key data</li>
<li>Use <a class="el" href="group__group__crypto__cli__functions.html#ga81fe41f71b97c14e6a4aefcaa78e3378">Cy_Crypto_Sha_Run</a> to calculate SHA digest of the data image</li>
<li>Use <a class="el" href="group__group__crypto__cli__functions.html#gac73a47f8656e1056686f461c68956fed">Cy_Crypto_Rsa_Proc</a> to decrypt present encrypted signature</li>
<li>Use <a class="el" href="group__group__crypto__cli__functions.html#gaeb5b9b79cbdb1e4b45dce7a27e269b5c">Cy_Crypto_Rsa_Verify</a> to verify the decrypted signature with calculated SHA digest</li>
</ul>
<p>Code example: </p><div class="fragment"><div class="line"></div><div class="line"><span class="preprocessor">    #define RSA_MODULO_LENGTH       2048u</span></div><div class="line"><span class="preprocessor">    #define RSA_MODULO_DATA_SIZE    (RSA_MODULO_LENGTH / 8)</span></div><div class="line"></div><div class="line">    <span class="keyword">typedef</span> <span class="keyword">struct</span></div><div class="line">    {</div><div class="line">        <a class="code" href="structcy__stc__crypto__rsa__pub__key__t.html">cy_stc_crypto_rsa_pub_key_t</a> publicKeyStruct;</div><div class="line">        uint8_t  moduloData[RSA_MODULO_DATA_SIZE];</div><div class="line">        uint8_t  expData   [32];</div><div class="line">        uint8_t  k1Data    [RSA_MODULO_DATA_SIZE+4];</div><div class="line">        uint8_t  k2Data    [RSA_MODULO_DATA_SIZE];</div><div class="line">        uint8_t  k3Data    [RSA_MODULO_DATA_SIZE];</div><div class="line">    } cy_stc_public_key_t;</div><div class="line"></div><div class="line">    <span class="comment">/* All data arrays should be 4-byte aligned */</span></div><div class="line">    cy_stc_public_key_t cy_publicKey =</div><div class="line">    {</div><div class="line">        .publicKeyStruct =</div><div class="line">        {</div><div class="line">            .moduloPtr          = 0,</div><div class="line">            .moduloLength       = RSA_MODULO_LENGTH,</div><div class="line">            .pubExpPtr          = 0,</div><div class="line">            .pubExpLength       = 24,</div><div class="line">            .barretCoefPtr      = NULL,</div><div class="line">            .inverseModuloPtr   = NULL,</div><div class="line">            .rBarPtr            = NULL</div><div class="line">        },</div><div class="line">        .moduloData =</div><div class="line">        {   <span class="comment">/* modulus in Little Endian for a public key - rsa_public.txt */</span></div><div class="line">            0xD9u, 0x94u, 0x94u, 0x38u, 0xA4u, 0xE0u, 0x50u, 0xA1u,</div><div class="line">            0xADu, 0xC5u, 0xE2u, 0x66u, 0xA9u, 0x7Fu, 0xE7u, 0xD7u,</div><div class="line">            0xA8u, 0x10u, 0x87u, 0x3Au, 0xBEu, 0xB3u, 0x0Eu, 0x6Au,</div><div class="line">            0xB2u, 0x8Bu, 0x2Eu, 0x8Du, 0xC2u, 0x45u, 0x41u, 0xA6u,</div><div class="line">            0xDBu, 0xEBu, 0x90u, 0x20u, 0x56u, 0xECu, 0xFDu, 0x8Cu,</div><div class="line">            0x23u, 0x09u, 0x13u, 0x5Du, 0x65u, 0xA2u, 0xADu, 0x9Du,</div><div class="line">            0x3Bu, 0xF2u, 0x5Bu, 0xF6u, 0xABu, 0x2Eu, 0xFEu, 0xF2u,</div><div class="line">            0x69u, 0x98u, 0x29u, 0x6Du, 0xD1u, 0x2Eu, 0x91u, 0x5Au,</div><div class="line">            0x65u, 0x83u, 0xF5u, 0x7Fu, 0x8Eu, 0x73u, 0xFFu, 0xA1u,</div><div class="line">            0x8Cu, 0x70u, 0x07u, 0xDFu, 0x4Du, 0xF4u, 0x79u, 0xB7u,</div><div class="line">            0x18u, 0xC1u, 0xA3u, 0x2Bu, 0x82u, 0x5Bu, 0x9Eu, 0xE2u,</div><div class="line">            0xF0u, 0xA0u, 0xB8u, 0xDAu, 0x19u, 0xADu, 0xBBu, 0x2Bu,</div><div class="line">            0xD5u, 0x07u, 0x5Au, 0x85u, 0x12u, 0x03u, 0xD8u, 0x60u,</div><div class="line">            0x53u, 0x3Du, 0xC6u, 0x34u, 0xE2u, 0x7Fu, 0x96u, 0x4Cu,</div><div class="line">            0x26u, 0x1Eu, 0x82u, 0xB1u, 0x85u, 0xC3u, 0x0Du, 0x54u,</div><div class="line">            0x68u, 0x37u, 0x97u, 0x58u, 0x19u, 0x36u, 0x43u, 0x9Cu,</div><div class="line">            0xD9u, 0xC3u, 0x42u, 0xEBu, 0xBEu, 0xE2u, 0x8Fu, 0x72u,</div><div class="line">            0xF1u, 0x5Eu, 0x2Au, 0x15u, 0x56u, 0x52u, 0xD4u, 0x6Du,</div><div class="line">            0x61u, 0x97u, 0x16u, 0xFEu, 0xC3u, 0xF9u, 0x17u, 0x3Cu,</div><div class="line">            0x37u, 0xD5u, 0xE1u, 0xA1u, 0x0Au, 0xB7u, 0xD9u, 0x65u,</div><div class="line">            0xA1u, 0x15u, 0xECu, 0xC7u, 0x39u, 0xECu, 0xEDu, 0x39u,</div><div class="line">            0x98u, 0x96u, 0x66u, 0x50u, 0x8Cu, 0x25u, 0xC3u, 0x29u,</div><div class="line">            0xB9u, 0xF8u, 0x25u, 0x55u, 0x92u, 0x7Au, 0xBFu, 0xFBu,</div><div class="line">            0x45u, 0x2Au, 0x28u, 0x8Au, 0xF9u, 0xE5u, 0xE2u, 0x30u,</div><div class="line">            0x72u, 0x0Eu, 0x0Au, 0x1Cu, 0x25u, 0x09u, 0x86u, 0x6Fu,</div><div class="line">            0xF6u, 0x6Fu, 0x15u, 0xEDu, 0x14u, 0xE6u, 0x1Eu, 0x53u,</div><div class="line">            0x5Au, 0x15u, 0x25u, 0xB9u, 0x5Eu, 0xC9u, 0xBAu, 0x48u,</div><div class="line">            0xA3u, 0xE3u, 0x93u, 0x62u, 0x3Cu, 0x6Cu, 0x3Cu, 0x83u,</div><div class="line">            0x17u, 0x29u, 0xFBu, 0xAEu, 0x91u, 0x47u, 0xC9u, 0x41u,</div><div class="line">            0x2Fu, 0xF9u, 0x82u, 0x29u, 0x7Bu, 0xB4u, 0x5Au, 0x93u,</div><div class="line">            0x01u, 0x95u, 0xDBu, 0x08u, 0x7Eu, 0x7Bu, 0x99u, 0x1Eu,</div><div class="line">            0xD4u, 0x25u, 0xD3u, 0x2Au, 0xF4u, 0xC7u, 0x9Fu, 0xB3u,</div><div class="line">        },</div><div class="line">        <span class="comment">/* Little endian exponent for a public key - rsa_public.txt */</span></div><div class="line">        .expData = { 0x01, 0x00, 0x01 },</div><div class="line">        .k1Data  = { 0, },</div><div class="line">        .k2Data  = { 0, },</div><div class="line">        .k3Data  = { 0, },</div><div class="line">    };</div><div class="line"></div><div class="line">    <span class="comment">/* Present encrypted signature of the image */</span></div><div class="line">    CY_ALIGN(4) uint8_t rsaEncryptedSign[RSA_MODULO_DATA_SIZE] =</div><div class="line">    {</div><div class="line">        0x12u, 0xCEu, 0x13u, 0x83u, 0x4Fu, 0xFFu, 0x39u, 0x9Bu,</div><div class="line">        0x33u, 0xDEu, 0xDCu, 0xDBu, 0x7Cu, 0x62u, 0xA5u, 0x10u,</div><div class="line">        0x24u, 0x07u, 0xEAu, 0x4Cu, 0x04u, 0x4Au, 0xCEu, 0x7Bu,</div><div class="line">        0x8Cu, 0xD8u, 0xD4u, 0x64u, 0xD1u, 0x98u, 0xA2u, 0x33u,</div><div class="line">        0x2Eu, 0xFFu, 0x06u, 0x13u, 0xD6u, 0x5Au, 0x50u, 0x3Cu,</div><div class="line">        0xA2u, 0x5Eu, 0xE3u, 0x11u, 0x54u, 0x7Cu, 0x6Au, 0x49u,</div><div class="line">        0x39u, 0xA3u, 0x62u, 0x02u, 0x66u, 0xB0u, 0x19u, 0x82u,</div><div class="line">        0xFBu, 0x5Du, 0x15u, 0xB2u, 0x0Bu, 0xF7u, 0xECu, 0x6Cu,</div><div class="line">        0xBEu, 0xEBu, 0x04u, 0x1Fu, 0x0Bu, 0x5Bu, 0x18u, 0x0Eu,</div><div class="line">        0x96u, 0x03u, 0xC4u, 0x1Eu, 0x56u, 0xB6u, 0x1Fu, 0xF2u,</div><div class="line">        0x08u, 0x7Au, 0x81u, 0x96u, 0x86u, 0xA4u, 0x93u, 0x5Du,</div><div class="line">        0x66u, 0x63u, 0x10u, 0xD5u, 0x9Bu, 0xA9u, 0xD7u, 0x52u,</div><div class="line">        0xCDu, 0xEFu, 0x23u, 0xDCu, 0x58u, 0xC7u, 0x3Du, 0x72u,</div><div class="line">        0x3Fu, 0x09u, 0x5Eu, 0x3Bu, 0x03u, 0xF9u, 0x91u, 0x10u,</div><div class="line">        0x63u, 0x2Au, 0x56u, 0xFAu, 0xCEu, 0x8Cu, 0x8Au, 0xBFu,</div><div class="line">        0xB5u, 0xA1u, 0xA7u, 0x0Fu, 0xBBu, 0xD8u, 0xACu, 0x7Fu,</div><div class="line">        0x43u, 0x3Cu, 0xBFu, 0x11u, 0xD8u, 0xAEu, 0x55u, 0xE7u,</div><div class="line">        0x23u, 0xF8u, 0xA4u, 0xE0u, 0x56u, 0xCFu, 0x3Fu, 0x21u,</div><div class="line">        0xA9u, 0xB6u, 0x01u, 0x34u, 0xDFu, 0xB6u, 0xDCu, 0xAAu,</div><div class="line">        0x29u, 0xB0u, 0x97u, 0x9Du, 0xD9u, 0xAAu, 0x47u, 0xD4u,</div><div class="line">        0xD9u, 0x4Au, 0x97u, 0x52u, 0x3Cu, 0xB9u, 0x36u, 0xDAu,</div><div class="line">        0xF6u, 0xA6u, 0x14u, 0x97u, 0xDEu, 0xE6u, 0x76u, 0xBFu,</div><div class="line">        0x1Bu, 0x23u, 0xDBu, 0x68u, 0x66u, 0xEAu, 0x0Eu, 0xC6u,</div><div class="line">        0xD3u, 0x52u, 0x05u, 0x86u, 0x26u, 0x04u, 0x31u, 0xCEu,</div><div class="line">        0xCFu, 0x8Du, 0x13u, 0x84u, 0x81u, 0xF2u, 0x7Bu, 0xB7u,</div><div class="line">        0xDCu, 0x93u, 0x23u, 0x93u, 0xD1u, 0x0Cu, 0xF4u, 0xDFu,</div><div class="line">        0x37u, 0x44u, 0x3Du, 0xD7u, 0xAFu, 0xBFu, 0xAFu, 0x32u,</div><div class="line">        0xE7u, 0x31u, 0x50u, 0x70u, 0x62u, 0xC3u, 0xABu, 0x31u,</div><div class="line">        0x51u, 0x28u, 0x2Bu, 0x0Bu, 0x31u, 0xC6u, 0xD3u, 0x0Fu,</div><div class="line">        0x74u, 0xE6u, 0x31u, 0x21u, 0xF0u, 0xA3u, 0x40u, 0x5Du,</div><div class="line">        0xEDu, 0xFFu, 0xC9u, 0xEBu, 0x5Au, 0x65u, 0xF3u, 0xCBu,</div><div class="line">        0x67u, 0x50u, 0x62u, 0x2Du, 0x8Au, 0xEAu, 0xC3u, 0xBDu,</div><div class="line">    };</div><div class="line"></div><div class="line">    <span class="comment">/* Previously calculated SHA-256 digest of the image */</span></div><div class="line">    CY_ALIGN(4) uint8_t sha256Digest[<a class="code" href="group__group__crypto__cli__srv__macros.html#ga82ff1a7671e4f0cf2026cbda5ef7e12a">CY_CRYPTO_SHA256_DIGEST_SIZE</a>] =</div><div class="line">    {</div><div class="line">        0xf4u, 0xcbu, 0x29u, 0x53u, 0xadu, 0xc2u, 0xbdu, 0x49u,</div><div class="line">        0x6bu, 0x43u, 0x28u, 0x2bu, 0x63u, 0xb7u, 0x0du, 0x16u,</div><div class="line">        0xa9u, 0xd4u, 0x90u, 0x65u, 0x6eu, 0x7bu, 0x6du, 0xb7u,</div><div class="line">        0x0bu, 0x17u, 0xefu, 0x60u, 0x02u, 0x12u, 0x0fu, 0x90u</div><div class="line">    };</div><div class="line"></div><div class="line">    <span class="comment">/* Temporary decryption buffer */</span></div><div class="line">    CY_ALIGN(4) uint8_t rsaOutput[RSA_MODULO_DATA_SIZE];</div><div class="line"></div><div class="line">    <a class="code" href="structcy__stc__crypto__context__rsa__t.html">cy_stc_crypto_context_rsa_t</a>     cryptoRsaContext;</div><div class="line">    <a class="code" href="structcy__stc__crypto__context__rsa__ver__t.html">cy_stc_crypto_context_rsa_ver_t</a> cryptoRsaVerContext;</div><div class="line">    <a class="code" href="group__group__crypto__enums.html#gaf08f93b8b21962a60f119157337b2113">cy_en_crypto_rsa_ver_result_t</a>   verResult;</div><div class="line">    <a class="code" href="group__group__crypto__enums.html#ga3a65158da3dc5cb6aa016ae599542aad">cy_en_crypto_status_t</a>           cryptoStatus;</div><div class="line"></div><div class="line"></div><div class="line">    cy_publicKey.publicKeyStruct.moduloPtr   = cy_publicKey.moduloData;</div><div class="line">    cy_publicKey.publicKeyStruct.pubExpPtr   = cy_publicKey.expData;</div><div class="line"></div><div class="line">    <span class="comment">/* NOTE: When signature placed as BIG-endian data (ex. generated by openssl), we should invert it for processing */</span></div><div class="line">    <a class="code" href="group__group__crypto__cli__functions.html#gabd4ba58c8fef2e5dc952995774cfb760">Cy_Crypto_InvertEndianness</a>(rsaEncryptedSign, 256);</div><div class="line"></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#gac73a47f8656e1056686f461c68956fed">Cy_Crypto_Rsa_Proc</a>(</div><div class="line">                        &amp;cy_publicKey.publicKeyStruct,</div><div class="line">                        (const uint32_t*)rsaEncryptedSign, sizeof(rsaEncryptedSign),</div><div class="line">                        (uint32_t *)rsaOutput,</div><div class="line">                        &amp;cryptoRsaContext);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#gac3fb202ea63ed0bec857424f8aac4b7e">Cy_Crypto_Sync</a>(<a class="code" href="group__group__crypto__cli__srv__macros.html#ga7cad37b39669bf7ec2994103962c73ad">CY_CRYPTO_SYNC_BLOCKING</a>);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div><div class="line">    <a class="code" href="group__group__crypto__cli__functions.html#gabd4ba58c8fef2e5dc952995774cfb760">Cy_Crypto_InvertEndianness</a>(rsaOutput, 256);</div><div class="line"></div><div class="line">    <span class="comment">/* Verify decrypted signature by calculated SHA digest from data image */</span></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#gaeb5b9b79cbdb1e4b45dce7a27e269b5c">Cy_Crypto_Rsa_Verify</a>(</div><div class="line">                        &amp;verResult,</div><div class="line">                        <a class="code" href="group__group__crypto__enums.html#gga66ead9efce36e261e978cad722bf2dbba2212390919051b39d22d567c508c6d1f">CY_CRYPTO_MODE_SHA256</a>,</div><div class="line">                        (const uint32_t*)sha256Digest,</div><div class="line">                        (const uint32_t*)rsaOutput, sizeof(rsaOutput),</div><div class="line">                        &amp;cryptoRsaVerContext);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div><div class="line">    <span class="comment">/* Wait crypto become available */</span></div><div class="line">    cryptoStatus = <a class="code" href="group__group__crypto__cli__functions.html#gac3fb202ea63ed0bec857424f8aac4b7e">Cy_Crypto_Sync</a>(CY_CRYPTO_SYNC_BLOCKING);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div><div class="line">    if (<a class="code" href="group__group__crypto__enums.html#ggaf08f93b8b21962a60f119157337b2113ae4b7e089501db168bf6ef127b8dbcb21">CY_CRYPTO_RSA_VERIFY_SUCCESS</a> == verResult)</div><div class="line">    {</div><div class="line">        <span class="comment">/* Verification OK */</span></div><div class="line">    }</div><div class="line">    <span class="keywordflow">else</span></div><div class="line">    {</div><div class="line">        <span class="comment">/* Verification FAILED */</span></div><div class="line">    }</div><div class="line"></div></div><!-- fragment --> <h1><a class="anchor" id="group_crypto_rsa_considerations"></a>
RSA Usage Considerations</h1>
<p>General RSA encryption and decryption is supported. <a class="el" href="group__group__crypto__cli__functions.html#gac73a47f8656e1056686f461c68956fed">Cy_Crypto_Rsa_Proc</a> encrypts or decrypts data based on the parameters passed to the function. If you pass in plain text and a public key, the output is encrypted (cipher text). If you pass in cipher text and a private key, the output is decrypted (plain text).</p>
<p>One parameter for this function call is a structure that defines the key: <a class="el" href="structcy__stc__crypto__rsa__pub__key__t.html" title="All fields for the context structure are internal. ">cy_stc_crypto_rsa_pub_key_t</a>. The four modulus and exponent fields are mandatory. They represent the data for either the public or private key as appropriate.</p>
<dl class="section note"><dt>Note</dt><dd>The <b>modulus</b> and <b>exponent</b> values in the <a class="el" href="structcy__stc__crypto__rsa__pub__key__t.html">cy_stc_crypto_rsa_pub_key_t</a> must be in little-endian order.<br />
 Use the <a class="el" href="group__group__crypto__cli__functions.html#gabd4ba58c8fef2e5dc952995774cfb760">Cy_Crypto_InvertEndianness</a> function to convert to or from little-endian order.</dd></dl>
<p>The remaining fields represent three pre-calculated coefficients that can reduce execution time by up to 5x. The fields are: coefficient for Barrett reduction, binary inverse of the modulus, and the result of (2^moduloLength mod modulo). These fields are optional, and can be set to NULL.</p>
<p>Calculate these coefficients with <a class="el" href="group__group__crypto__cli__functions.html#gaf7d03e6a13f42bae1fbbcf6c05730129">Cy_Crypto_Rsa_CalcCoefs</a>. Pass them in the address of the key structure with the modulus and exponent values for the key. The function returns the coefficients for the key in the key structure, replacing any previous values.</p>
<p>The RSA functionality also implements functions to decrypt a signature using a public key. This signature must follow the RSASSA-PKCS-v1_5 standard. The signature must contain a SHA digest (hash). MD2, MD4, and MD5 message digests are not supported.</p>
<p>An encrypted signature is stored as big-endian data. It must be inverted for RSA processing. To use the provided signature decryption, firmware must</p><ol type="1">
<li>Calculate the SHA digest of the data to be verified with <a class="el" href="group__group__crypto__cli__functions.html#ga81fe41f71b97c14e6a4aefcaa78e3378">Cy_Crypto_Sha_Run</a>.</li>
<li>Ensure that the RSA signature is in little-endian format. Use <a class="el" href="group__group__crypto__cli__functions.html#gabd4ba58c8fef2e5dc952995774cfb760">Cy_Crypto_InvertEndianness</a>.</li>
<li>Decrypt the RSA signature with a public key, by calling <a class="el" href="group__group__crypto__cli__functions.html#gac73a47f8656e1056686f461c68956fed">Cy_Crypto_Rsa_Proc</a>.</li>
<li>Invert the byte order of the output, to return to big-endian format. Use <a class="el" href="group__group__crypto__cli__functions.html#gabd4ba58c8fef2e5dc952995774cfb760">Cy_Crypto_InvertEndianness</a>.</li>
<li>Call <a class="el" href="group__group__crypto__cli__functions.html#gaeb5b9b79cbdb1e4b45dce7a27e269b5c">Cy_Crypto_Rsa_Verify</a> (which requires data in big-endian format).</li>
</ol>
<h1><a class="anchor" id="group_crypto_irq_implements"></a>
Implementing Crypto Interrupts</h1>
<p>The Crypto driver uses three interrupts:</p><ul>
<li>A notify interrupt when data is ready for a cryptographic operation</li>
<li>A release interrupt when a cryptographic operation is complete</li>
<li>An error interrupt if the server encounters a hardware error</li>
</ul>
<p>You can modify default behavior for each interrupt.</p>
<p><b>Notify Interrupt:</b> the Crypto server has a default ISR to handle this interrupt, <a class="el" href="group__group__crypto__srv__functions.html#ga247aad529a2ad367f757c4b2aa1995da">Cy_Crypto_Server_GetDataHandler</a>. The default ISR clears the interrupt, retrieves the data from the IPC channel, and dispatches control to the desired cryptographic operation.</p>
<p>To use the default handler, set the <a class="el" href="structcy__stc__crypto__config__t.html#a4130639046fb3a253bf8898f5dc23f7b">userGetDataHandler </a> field of the <a class="el" href="structcy__stc__crypto__config__t.html" title="The Crypto configuration structure. ">cy_stc_crypto_config_t</a> structure to NULL.</p>
<p>To override, populate this field with your ISR. Then call Crypto Server Start function. Your ISR can perform additional tasks required by your application logic, but must also call <a class="el" href="group__group__crypto__srv__functions.html#ga247aad529a2ad367f757c4b2aa1995da">Cy_Crypto_Server_GetDataHandler</a> to dispatch the data to the correct cryptographic operation.</p>
<dl class="section note"><dt>Note</dt><dd><a class="el" href="group__group__crypto__srv__functions.html#gab3a5d2a4bd48f96e41d47117aabdfef6">Cy_Crypto_Server_Process</a> should be performed from this ISR or from any other task in the multi-task environment.</dd></dl>
<div class="fragment"><div class="line">    <span class="keywordtype">void</span> My_Crypto_Server_GetDataHandler(<span class="keywordtype">void</span>)</div><div class="line">    {</div><div class="line">        uint32_t interruptMasked;</div><div class="line"></div><div class="line">        <span class="comment">/*</span></div><div class="line"><span class="comment">         * Check that there is really the IPC Crypto Notify interrupt,</span></div><div class="line"><span class="comment">         * because the same line can be used for the IPC Crypto Release interrupt.</span></div><div class="line"><span class="comment">         */</span></div><div class="line">        interruptMasked = Cy_IPC_Drv_ExtractAcquireMask(<a class="code" href="group__group__ipc__functions.html#ga423a1a0df8939384794e95f7e05b1e03">Cy_IPC_Drv_GetInterruptStatusMasked</a>(</div><div class="line">                                             <a class="code" href="group__group__ipc__functions.html#gaea293f27dc3d6d69eb40ef2d8f5c8d2b">Cy_IPC_Drv_GetIntrBaseAddr</a>(cy_crypto_serverContext-&gt;acquireNotifierChannel)));</div><div class="line"></div><div class="line">        <span class="keywordflow">if</span> ((1uL &lt;&lt; (cy_crypto_serverContext-&gt;ipcChannel)) == interruptMasked )</div><div class="line">        {</div><div class="line">            <span class="comment">/* Load IPC message and save it to process*/</span></div><div class="line">            <a class="code" href="group__group__crypto__srv__functions.html#ga247aad529a2ad367f757c4b2aa1995da">Cy_Crypto_Server_GetDataHandler</a>();</div><div class="line"></div><div class="line">            <span class="comment">/* Process given message */</span></div><div class="line">            <a class="code" href="group__group__crypto__srv__functions.html#gab3a5d2a4bd48f96e41d47117aabdfef6">Cy_Crypto_Server_Process</a>();</div><div class="line"></div><div class="line">            <a class="code" href="group__group__ipc__functions.html#ga408e08c5842189246a35ca2be89d62ea">Cy_IPC_Drv_ClearInterrupt</a>(<a class="code" href="group__group__ipc__functions.html#gaea293f27dc3d6d69eb40ef2d8f5c8d2b">Cy_IPC_Drv_GetIntrBaseAddr</a>(cy_crypto_serverContext-&gt;acquireNotifierChannel),</div><div class="line">                                      <a class="code" href="group__group__ipc__macros.html#ga8c02b33010a796cc0d610491bda52827">CY_IPC_NO_NOTIFICATION</a>, interruptMasked);</div><div class="line">        }</div><div class="line">    }</div></div><!-- fragment --><div class="fragment"><div class="line">    <span class="comment">/* Scenario: Configure Server and Client as follows:</span></div><div class="line"><span class="comment">     * Server:</span></div><div class="line"><span class="comment">     *  - IPC channel for communication: 9</span></div><div class="line"><span class="comment">     *  - IPC interrupt structure used for new request notifications: 1</span></div><div class="line"><span class="comment">     *  - Data request handler: myGetDataHandler</span></div><div class="line"><span class="comment">     *  - Hardware errors handler: default</span></div><div class="line"><span class="comment">     * Client:</span></div><div class="line"><span class="comment">     *  - IPC channel for communication: 9</span></div><div class="line"><span class="comment">     *  - IPC interrupt structure used for data ready notifications: 2</span></div><div class="line"><span class="comment">     *  - Data Complete callback: not used</span></div><div class="line"><span class="comment">     */</span></div><div class="line"></div><div class="line"><span class="preprocessor">    #define MY_CHAN_CRYPTO         (uint32_t)(9u)    </span><span class="comment">/* IPC data channel for the Crypto */</span><span class="preprocessor"></span></div><div class="line"><span class="preprocessor">    #define MY_INTR_CRYPTO_SRV     (uint32_t)(1u)    </span><span class="comment">/* IPC interrupt structure for the Crypto server */</span><span class="preprocessor"></span></div><div class="line"><span class="preprocessor">    #define MY_INTR_CRYPTO_CLI     (uint32_t)(2u)    </span><span class="comment">/* IPC interrupt structure for the Crypto client */</span><span class="preprocessor"></span></div><div class="line"></div><div class="line"><span class="preprocessor">    #define MY_INTR_CRYPTO_SRV_MUX (IRQn_Type)(2u)   </span><span class="comment">/* CM0+ IPC interrupt mux number the Crypto server */</span><span class="preprocessor"></span></div><div class="line"><span class="preprocessor">    #define MY_INTR_CRYPTO_CLI_MUX (IRQn_Type)(3u)   </span><span class="comment">/* CM0+ IPC interrupt mux number the Crypto client */</span><span class="preprocessor"></span></div><div class="line"><span class="preprocessor">    #define MY_INTR_CRYPTO_ERR_MUX (IRQn_Type)(4u)   </span><span class="comment">/* CM0+ ERROR interrupt mux number the Crypto server */</span><span class="preprocessor"></span></div><div class="line"></div><div class="line">    <span class="keyword">const</span> <a class="code" href="structcy__stc__crypto__config__t.html">cy_stc_crypto_config_t</a> myCryptoConfig =</div><div class="line">    {</div><div class="line">        <span class="comment">/* .ipcChannel             */</span> MY_CHAN_CRYPTO,</div><div class="line">        <span class="comment">/* .acquireNotifierChannel */</span> MY_INTR_CRYPTO_SRV,</div><div class="line">        <span class="comment">/* .releaseNotifierChannel */</span> MY_INTR_CRYPTO_CLI,</div><div class="line"></div><div class="line">        <span class="comment">/* .releaseNotifierConfig */</span> {</div><div class="line"><span class="preprocessor">        #if (CY_CPU_CORTEX_M0P)</span></div><div class="line">            <span class="comment">/* .intrSrc            */</span> MY_INTR_CRYPTO_CLI_MUX,</div><div class="line">            <span class="comment">/* .cm0pSrc            */</span> cpuss_interrupts_ipc_2_IRQn, <span class="comment">/* depends on selected releaseNotifierChannel value */</span></div><div class="line"><span class="preprocessor">        #else</span></div><div class="line">            <span class="comment">/* .intrSrc            */</span> cpuss_interrupts_ipc_2_IRQn, <span class="comment">/* depends on selected releaseNotifierChannel value */</span></div><div class="line"><span class="preprocessor">        #endif</span></div><div class="line">            <span class="comment">/* .intrPriority       */</span> 2u,</div><div class="line">        },</div><div class="line"></div><div class="line">        <span class="comment">/* .userCompleteCallback   */</span> NULL,</div><div class="line">        <span class="comment">/* .userGetDataHandler     */</span> My_Crypto_Server_GetDataHandler,</div><div class="line">        <span class="comment">/* .userErrorHandler       */</span> NULL,</div><div class="line"></div><div class="line">        <span class="comment">/* .acquireNotifierConfig */</span> {</div><div class="line"><span class="preprocessor">        #if (CY_CPU_CORTEX_M0P)</span></div><div class="line">            <span class="comment">/* .intrSrc            */</span> MY_INTR_CRYPTO_SRV_MUX,      <span class="comment">/* to use with DeepSleep mode should be in DeepSleep capable muxer&#39;s range */</span></div><div class="line">            <span class="comment">/* .cm0pSrc            */</span> cpuss_interrupts_ipc_1_IRQn, <span class="comment">/* depends on selected acquireNotifierChannel value */</span></div><div class="line"><span class="preprocessor">        #else</span></div><div class="line">            <span class="comment">/* .intrSrc            */</span> cpuss_interrupts_ipc_1_IRQn, <span class="comment">/* depends on selected acquireNotifierChannel value */</span></div><div class="line"><span class="preprocessor">        #endif</span></div><div class="line">            <span class="comment">/* .intrPriority       */</span> 2u,</div><div class="line">        },</div><div class="line">        <span class="comment">/* .cryptoErrorIntrConfig */</span> {</div><div class="line"><span class="preprocessor">        #if (CY_CPU_CORTEX_M0P)</span></div><div class="line">            <span class="comment">/* .intrSrc            */</span> MY_INTR_CRYPTO_ERR_MUX,</div><div class="line">            <span class="comment">/* .cm0pSrc            */</span> cpuss_interrupt_crypto_IRQn,</div><div class="line"><span class="preprocessor">        #else</span></div><div class="line">            <span class="comment">/* .intrSrc            */</span> cpuss_interrupt_crypto_IRQn,</div><div class="line"><span class="preprocessor">        #endif</span></div><div class="line">            <span class="comment">/* .intrPriority       */</span> 2u,</div><div class="line">        }</div><div class="line">    };</div><div class="line"></div><div class="line">    <a class="code" href="structcy__stc__crypto__server__context__t.html">cy_stc_crypto_server_context_t</a>  myCryptoServerContext;</div><div class="line">    <a class="code" href="group__group__crypto__enums.html#ga3a65158da3dc5cb6aa016ae599542aad">cy_en_crypto_status_t</a>           cryptoStatus;</div><div class="line"></div><div class="line">    cryptoStatus = Cy_Crypto_Server_Start_Base(&amp;myCryptoConfig, &amp;myCryptoServerContext);</div><div class="line"></div><div class="line">    <span class="comment">/* ... check for errors... */</span></div><div class="line"></div></div><!-- fragment --><p> <b>Release Interrupt:</b> The Crypto driver includes a handler for this interrupt. The interrupt handler clears the interrupt and calls a user-provided callback routine. You cannot override this interrupt handler. By default the interrupt is disabled.</p>
<p>To use default behavior (interrupt disabled), set the <a class="el" href="structcy__stc__crypto__config__t.html#a52ff77b99e58e9f238f260a50740be7b">userCompleteCallback </a> field of the <a class="el" href="structcy__stc__crypto__config__t.html" title="The Crypto configuration structure. ">cy_stc_crypto_config_t</a> structure to NULL. To enable the interrupt, populate this field with your callback function. Then call <a class="el" href="group__group__crypto__cli__functions.html#ga79963cfa80b828a77a85bd8e144af2e1">Cy_Crypto_Init</a>. If the callback function is not NULL, the Init function enables the interrupt, and default behavior calls your routine.</p>
<p>When performing cryptographic operations, firmware must ensure the operation is complete before acting on the results. If the release interrupt is disabled, typically calls to <a class="el" href="group__group__crypto__cli__functions.html#gac3fb202ea63ed0bec857424f8aac4b7e">Cy_Crypto_Sync</a> should be blocking. If the interrupt is enabled, your callback function is called when the operation is complete. This lets you avoid blocking calls to <a class="el" href="group__group__crypto__cli__functions.html#gac3fb202ea63ed0bec857424f8aac4b7e">Cy_Crypto_Sync</a>.</p>
<p><b>Error Interrupt:</b> The Crypto server has a default ISR to handle this interrupt. It clears the interrupt and sets an internal flag that an error has occurred.</p>
<p>To use the default handler, set the userErrorHandler field of the <a class="el" href="structcy__stc__crypto__config__t.html" title="The Crypto configuration structure. ">cy_stc_crypto_config_t</a> structure to NULL. To override, populate this field with your ISR. Then call Crypto Server Start function.</p>
<p>Your ISR must call <a class="el" href="group__group__crypto__srv__functions.html#ga36706e765604590078a2a55c6355b897">Cy_Crypto_Server_ErrorHandler</a>, and can perform any additional tasks required by your application logic. </p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="groups"></a>
API Reference</h2></td></tr>
<tr class="memitem:group__group__crypto__cli__srv__macros"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__crypto__cli__srv__macros.html">Macros</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:group__group__crypto__cli__srv__functions"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__crypto__cli__srv__functions.html">Functions</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:group__group__crypto__cli__srv__data__structures"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__crypto__cli__srv__data__structures.html">Data Structures</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part
<div id="nav-path" class="navpath">
    <ul>
        <li class="footer">
            Generated for <b>MTB CAT1 Peripheral driver library</b> by <b>Cypress Semiconductor Corporation</b>.
            All rights reserved.
        </li>
    </ul>
</div>
-->
</body>
</html>
